package cn.doitedu.rtdw.yanggekun;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;

import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

public class JudgeUtils {

    static Set<String> entryTypeP = new HashSet<>(Arrays.asList("P01", "P02", "P03", "P04", "P05", "P06", "P07", "P08"));
    static Set<String> entryTypeT = new HashSet<>(Arrays.asList("T01", "T02", "T05", "T06", "T07"));
    static Set<String> entryTypeS = new HashSet<>(Arrays.asList("S01", "S02", "S03", "S04", "S05", "S06", "S07", "S08", "S09", "S10", "S11", "S13", "RS01", "RS03", "RS04", "RS02", "S15", "S18", "S19"));


    /*  1. 未关入库单
       super_class = 1 AND receive_status = 0
       AND entry_type IN ('P01', 'P02', 'P03', 'P04', 'P05', 'P06', 'P07', 'P08')
       AND receive_location_code = 'W0A8'
       AND plan_receive_date >= DATE_SUB(CURRENT_DATE, 1)
       AND plan_receive_date <= CURRENT_DATE
       AND create_time >= DATE_SUB(CURRENT_DATE, 6),
    */
    public static boolean judgeWeiGuan(Order order) {
        return order.getSuper_class() == 1
                && order.getReceive_status() == 0
                && entryTypeP.contains(order.getEntry_type())
                && order.getPlan_receive_date().compareTo(DateUtils.addDays(new Date(System.currentTimeMillis()), -1)) >= 0
                && order.getPlan_receive_date().compareTo(new Date(System.currentTimeMillis())) <= 0
                && order.getCreate_time().compareTo(DateUtils.addDays(new Date(System.currentTimeMillis()), -6)) >= 0;
    }

    /*  2. 未清入库单
    super_class = 1 AND receive_status < 2
    AND entry_type IN ('P01', 'P02', 'P03', 'P04', 'P05', 'P06', 'P07', 'P08')
    AND plan_receive_date >= DATE_SUB(CURRENT_DATE, 1)
    AND plan_receive_date <= CURRENT_DATE
    AND create_time >= DATE_SUB(CURRENT_DATE, 6),
    */
    public static boolean judgeWeiQing(Order order) {
        return order.getSuper_class() == 1
                && order.getReceive_status() < 2
                && entryTypeP.contains(order.getEntry_type())
                && order.getPlan_receive_date().compareTo(DateUtils.addDays(new Date(System.currentTimeMillis()), -1)) >= 0
                && order.getPlan_receive_date().compareTo(new Date(System.currentTimeMillis())) <= 0
                && order.getCreate_time().compareTo(DateUtils.addDays(new Date(System.currentTimeMillis()), -6)) >= 0;
    }

    /*  3. 仓库调拨单
        super_class = 1
        AND receive_status = 0
        AND entry_type IN ('T01', 'T02', 'T05', 'T06', 'T07')
        AND business_type = 12
        AND create_time >= DATE_SUB(CURRENT_DATE, 29)
        AND plan_receive_date >= DATE_SUB(CURRENT_DATE, 6)
        AND plan_receive_date <= DATE_SUB(CURRENT_DATE, 0),
     */
    public static boolean judgeDiaoBo(Order order) {
        return order.getSuper_class() == 1
                && order.getReceive_status() == 0
                && entryTypeT.contains(order.getEntry_type())
                && order.getPlan_receive_date().compareTo(DateUtils.addDays(new Date(System.currentTimeMillis()), -1)) >= 0
                && order.getPlan_receive_date().compareTo(new Date(System.currentTimeMillis())) <= 0
                && order.getCreate_time().compareTo(DateUtils.addDays(new Date(System.currentTimeMillis()), -6)) >= 0;
    }

    /*  4. 待上架任务
        super_class = 1
        AND shelf_status = 0
        AND receive_status IN (1, 2)
        AND plan_receive_date >= date_sub(current_date, 1)
        AND plan_receive_date  <= date_sub(current_date, 1)
        AND create_time >= date_sub(current_date, 6)
        AND business_type <> '01',
     */
    public static boolean judgeDaishangJia(Order order) {
        return order.getSuper_class() == 1
                && order.getShelf_status() == 0
                && (order.getReceive_status() == 1 || order.getReceive_status() == 2)
                && order.getPlan_receive_date().compareTo(DateUtils.addDays(new Date(System.currentTimeMillis()), -1)) >= 0
                && order.getPlan_receive_date().compareTo(new Date(System.currentTimeMillis())) <= 0
                && order.getCreate_time().compareTo(DateUtils.addDays(new Date(System.currentTimeMillis()), -6)) >= 0;
    }


    /*  5. 客户退单
        super_class = 1
        AND receive_status = 0
        AND entry_type IN ('S01', 'S02', 'S03', 'S04', 'S05', 'S06', 'S07', 'S08', 'S09', 'S10', 'S11', 'S13', 'RS01', 'RS03', 'RS04', 'RS02', 'S15', 'S18', 'S19')
        AND business_type = 'R18'
        AND create_time >= date_sub(current_date, 6),
     */
    public static boolean judgeTuidan(Order order) {
        return order.getSuper_class() == 1
                && order.getShelf_status() == 0
                && entryTypeS.contains(order.getEntry_type())
                && "R18".equals(order.getBusiness_type())
                && order.getCreate_time().compareTo(DateUtils.addDays(new Date(System.currentTimeMillis()), -6)) >= 0;
    }

}
